<?php

	class RegisterView {
	
		private $_usernameInput = "usernameInput";
		private $_passwordInput = "passwordInput";
		private $_confirmpasswordInput = "confirmpasswordInput";
		private $_emailInput = "emailInput";
		private $_registerInput = "registerInput";
		private $_activeController = "activeController";
		
		// Function used to create the Register form.
		// Returns XHTML string
			public function DoRegisterForm() {
	
			return "
			<form method='get'>
				<div class=registercontainer><div class=registerusername>Username:</div><input type='text' maxlength='20' name=$this->_usernameInput></input>
				<div class=registerpassword>Password:</div><input type='password'  maxlength='20' name=$this->_passwordInput></input>
				<div class=registerpassword>Confirm Password:</div><input type='password'  maxlength='20' name=$this->_confirmpasswordInput></input>
				<div class=registerhelp>Your Password need to be atleast six characters long, and contain atleast one number, one uppercase letter, and one lowercase letter</div>
				<div class=registeremail>Email:</div><input type='text' maxlength='60' name=$this->_emailInput></input>
				<div class=registerbutton><input type='submit' name=$this->_registerInput value='Register'/></div>
				<input type='hidden' name=$this->_activeController value='Register'/></div>
			</form>";
		}
		
		//Returns the username input if it exists
		public function GetUserName(){
			if (isset( $_GET[$this->_usernameInput])) {
				return $_GET[$this->_usernameInput];
			}
			return null;
		}
		
		//Returns the password input if it exists
		public function GetPassword(){
			if (isset( $_GET[$this->_passwordInput])) {
				return $_GET[$this->_passwordInput];		
				}
			return null;
		}
		
		//Returns the email input if it exists
		public function GetEmail(){
			if (isset( $_GET[$this->_emailInput])){
				return $_GET[$this->_emailInput];
				}
			return null;
		}
		
		//Returns true if the user pressed the Register button
		public function PressedRegister(){
			if (isset( $_GET[$this->_registerInput]) == true) {
				return true;
			}
			return false;
		}
		
		//Validates the info in Get
		public function CheckInfo(){
			if(Validate::ValidatePassword($_GET[$this->_passwordInput]) == false){
				return "Your password is in an incorrect format";
			}
			else if ($_GET[$this->_passwordInput] != $_GET[$this->_confirmpasswordInput] ){
				return "Your passwords doesn't match";
			}
			else if(strlen($_GET[$this->_usernameInput]) == 0){
				return "No Username Entered";
			}
			else if(Validate::ValidateEmail($_GET[$this->_emailInput]) == false){
				return "Incorrect Email";
			}
			return true;
		}
		
		public function AddMessageUserCreated(){
			return "New user created. You should be able to log in with your userinfo immediately";
		}
		
		public function AddMessageError(){
			return "An error occured when your new user was being created, please try again";
		}
		
		public function AddHeader(){
			return "<div id=register><div class=registerheader>Register New User: </div>";
		}
	
	}


